package com.moyun.controller.system;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moyun.common.annotation.OperLog;
import com.moyun.common.aspect.BusinessType;
import com.moyun.model.common.PageDTO;
import com.moyun.model.common.PageParam;
import com.moyun.model.common.PageResult;
import com.moyun.model.common.R;
import com.moyun.model.po.system.SysRolePrivilegeEntity;
import com.moyun.service.system.SysRolePrivilegeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 用户角色关联表 前端控制器
 * </p>
 *
 * @author yangboxuan
 * @since 2021-07-02
 */
@Api(tags = "系统角色权限")
@RestController
@RequestMapping("/security/sys-role-privilege")
public class SysRolePrivilegeController {
    @Autowired
    private SysRolePrivilegeService sysRolePrivilegeEntityService;


    /**
     * @return com.moyun.common.web.JsonResult
     * @Author yangboxuan
     * @Description 带条件的分页查询
     * @Date 2021-07-02
     * @Param [params]
     **/
    @ApiOperation("带条件的分页查询")
    @PostMapping("/select-condition")
    @OperLog(operModul = "系统角色权限模块", operType = BusinessType.QUERY, operDesc = "分页查询")
    public R selectCondition(@RequestBody PageParam<SysRolePrivilegeEntity> params) {
        PageDTO pageParams = params.getPageParams();
        Page<SysRolePrivilegeEntity> page = new Page<>(pageParams.getCurrent(), pageParams.getSize());
        SysRolePrivilegeEntity sysRolePrivilegeEntity = params.getEntityParams();
        QueryWrapper<SysRolePrivilegeEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(sysRolePrivilegeEntity.getRoleId() != null, "role_id", sysRolePrivilegeEntity.getRoleId());
        queryWrapper.eq(sysRolePrivilegeEntity.getPrivilegeId() != null, "privilege_id", sysRolePrivilegeEntity.getPrivilegeId());
        this.sysRolePrivilegeEntityService.page(page, queryWrapper);
        return R.ok(new PageResult<SysRolePrivilegeEntity>(page.getTotal(), page.getRecords()));
    }


}

